<?php


namespace App\Models;


use App\Traits\DateTimeModel;
use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    use DateTimeModel;

    protected $table = 'customer';
    protected $fillable = ['code', 'name', 'short_name', 'license', 'remark', 'assure'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     * @author luffyzhao@vip.126.com
     */
    public function logs(){
        return $this->hasMany(CustomerRecordLog::class);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function users(){
        return $this->hasMany(CustomerUser::class);
    }

    /**
     * 是否正常
     * @return bool
     */
    public function isNormal(){
        return $this->canFrozen();
    }

    /**
     * 可以修改
     * @return bool
     */
    public function canUpdate(){
        return $this->getAttribute('status') === 0 || $this->getAttribute('status') === 2;
    }
    /**
     * 可以确认
     * @return bool
     */
    public function canConfirm(){
        return $this->getAttribute('status') === 0;
    }
    /**
     * 可以审核
     * @return bool
     */
    public function canExamine(){
        return $this->getAttribute('status') === 1;
    }
    /**
     * 可以驳回
     * @return bool
     */
    public function canReject(){
        return $this->getAttribute('status') === 1;
    }
    /**
     * 可以冻结
     * @return bool
     */
    public function canFrozen(){
        return $this->getAttribute('status') === 3;
    }
    /**
     * 可以解冻
     * @return bool
     */
    public function canThaw(){
        return $this->getAttribute('status') === 4;
    }

    /**
     * 可以删除
     * @return bool
     */
    public function canDelete()
    {
        return $this->getAttribute('status') === 0 || $this->getAttribute('status') === 2;
    }
}
